<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
@IMPORT url("css/core.css");
</style>
<script type="text/javascript" src="js/jquery-1.11.0.js">
</script>
<script type="text/javascript">
	function buySubmit(){
		var id = <%=request.getParameter("id")%>
		var numbers = $("#gdnumber").val();
		var sf = $("#sf_id").val();
		var city = $("#city_id").val();
		var dtail = $("#dtail_id").val();
		var total_price = $("#total_price").text();
		
		$.get("GoodBuyServlet",{id:id,number:numbers,sf:sf,city:city,dtail:dtail,price:total_price},function(data){
			location = "buyresult.jsp";
		});
	}
	
	$(function(){
		
		$("#gdnumber").change(function(){
			murePrice();
		});
		
		//计算价格
		function murePrice(){
			var price = $("#gdprice").text();
			var number = $("#gdnumber").val();
			//计算总的价格
			var totalPrice = price*number;
			$("#total_price").text(totalPrice);
		}
		
		function init(){
			var id = <%=request.getParameter("id")%>
			//{"id_gd":"3","imge_gd":"images/list1.jpg","name_gd":"高清数据线","number_gd":"10","price_gd":"200","state":"1"
			$.get("QueryGoodsServlet",{id:id,type:1},function(data){
				$("#gdname").text(data.name_gd);
				$("#gdimg").attr("src",data.imge_gd);
				$("#gdprice").text(data.price_gd);
				
				murePrice();
				
			},"json");
		}
		init();
	});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>"/>
</head>
<body>
	<table>
		<thead>
			<tr>
			<th>商品名称</<th>
			<th>商品图片</<th>
			<td>商品价格</td>
			<td>商品数量</td>
			<td>订单价格</td>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td id="gdname"></td>
				<td><img id="gdimg"></td>
				<td id="gdprice">0</td>
				<td><input id="gdnumber" value="1"></td>
				<td id="total_price">0</td>
			</tr>
		</tbody>
	</table>
	<br>
	省份:<input id="sf_id"><br>
	城市:<input id="city_id"><br>
	详细地址:<input id="dtail_id"><br>
	<input onclick="buySubmit()" type="button" value="确定">
</body>
</html>